<div class="tmd-doc">
<p></p>
<h1 class="tmd-header-1">
switch 1
</h1>
<p></p>
<div id="question" class="tmd-base">
<div class="tmd-usual">
What does the following program print?
</div>
<p></p>
<pre class="tmd-code line-numbers">
<code class="language-go">package main

func f() bool {
	return false
}

func main() {
	switch f() //
	{
	case true:
		println(1)
	case false:
		println(0)
	}
}
</code></pre>
</div>
<p></p>
<div class="tmd-usual">
Choices:
</div>
<p></p>
<input type="radio" id="choiceA" name="choice" class="choice">
<input type="radio" id="choiceB" name="choice" class="choice">

<div id="choices">

<ul style="list-style-type:none;">
<li><label for="choiceA">0</label></li>
<li><label for="choiceB">1</label></li>
</ul>

</div><p></p>
<div id="answer" class="tmd-base">
<p></p>
<div class="tmd-usual">
Answer: 1
</div>
<p></p>
<div class="tmd-usual">
Run it on <a href="https://go.dev/play/p/vfpqxb6FY2L">Go play</a>.
</div>
<p></p>
<div class="tmd-usual">
Key points:
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
Go compilers will <a href="https://go101.org/article/line-break-rules.html">insert semicolons automatically</a> for Go code in compiling.
</div>
</li>
<li class="tmd-list-item">
<div class="tmd-usual">
The default switch expression is <code class="tmd-code-span">true</code> (of the builtin type <code class="tmd-code-span">bool</code>).
</div>
</li>
</ul>
<p></p>
<div class="tmd-usual">
The small details mentioned above are just two in about 100 ones collected in the <a href="https://go101.org/details-and-tips/101.html">Go Details &amp; Tips 101</a> book.
</div>
<p></p>
</div>
<p></p>
</div>
